import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int f = sc.nextInt();
        int count = 0;
        int flag = 31;
        for(int i = c; i <= flag; i++){
            if(b == 2){
                if((a%4==0 && a%100!=0) || (a%400==0)){
                    flag = 29;
                }else{
                    flag = 28;
                }
            }
            if(b == 4 || b == 6 || b == 9 || b == 11) flag = 30;
            if(check(a, b, i)) {
                System.out.println(a + " " + b + " " + i);
                count++;
            }
            if(i == flag && b != 12){
                b++;
                i = 0;
            }
            if(i == flag && b == 12){
                a++;
                b = 1;
                i = 0;
            }
            if(a == d && b == e && i == f) break;
        }
    }
    public static boolean check(int a, int b, int c){
        int[] arr = new int[10];
        for(int i = 0; a != 0; i++){
            arr[i] = a % 10;
            a = a / 10;
        }
        arr[4] = b % 10;
        arr[5] = b / 10;
        arr[6] = c % 10;
        arr[7] = c / 10;
        double sum = 0;
        for(int i : arr){
            sum += i;
        }
        double ret = Math.sqrt(sum);
        return ret == (int)ret;
    }
}